﻿#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include <string>
#include<unordered_map>
using namespace std;
string modifyString(string s)
{
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '?')
		{
			for (char ch = 'a'; ch <= 'z'; ch++)
			{
				if ((i == 0 || ch != s[i - 1]) && ((i == s.size() - 1) || ch != s[i + 1]))
				{
					s[i] = ch;
				}
			}
		}
	}
	return s;
}
int findPoisonedDuration(vector<int>& timeSeries, int duration) 
{
	int ret = 0;
	for (int i = 1; i < timeSeries.size(); i++)
	{
		int tmp = timeSeries[i] - timeSeries[i - 1];
		if (tmp >= duration) ret += duration;
		else ret += tmp;
	}
	return ret + duration;
}
string convert(string s, int numRows)
{
	// 处理边界情况
	if (numRows == 1) return s;
	string ret;
	int d = 2 * numRows - 2, n = s.size();
	// 1. 先处理第⼀⾏
	for (int i = 0; i < n; i += d)
		ret += s[i];
	// 2. 处理中间⾏
	for (int k = 1; k < numRows - 1; k++) // 枚举每⼀⾏
	{
		for (int i = k, j = d - k; i < n || j < n; i += d, j += d)
		{
			if (i < n) ret += s[i];
			if (j < n) ret += s[j];
		}
	}
	// 3. 处理最后⼀⾏
	for (int i = numRows - 1; i < n; i += d)
		ret += s[i];
	return ret;
}
string countAndSay(int n) 
{
	string ret="1";
	while (n--)
	{
		string tmp;
		int left = 0, right = 0;
		while (right < ret.size())
		{
			while(ret[left]==ret[right])
			{
				right++;
			}
			tmp += to_string(right - left) + ret[left];
			left = right;
		}
		ret = tmp;
	}
	return ret;
}
int minNumberOfFrogs(string croakOfFrogs) 
{
	int count[5] = { 0 };
	unordered_map<char,int> hash;
	string s = "croak";
	for (int i = 0; i < s.size(); i++)
	{
		hash[s[i]] =i;
	}
	for (int i = 0; i < croakOfFrogs.size(); i++)
	{
		if (croakOfFrogs[i] == 'c')
		{
			if (count[hash['k']] > 0)
			{
				count[hash['k']]--;
			}
			count[hash['c']]--;
		}
		else
		{
			for (int j = 1; j < s.size(); i++)
			{
				if (s[j] == croakOfFrogs[i])
				{
					if (count[hash[s[j - 1]]] == 0)
					{
						return -1;
					}
					count[hash[s[j - 1]]]--;
					count[hash[s[j]]]++;
					break;
				}
			}
		}
	}
	for (int i = 0; i < 4; i++)
	{
		if (count[i] != 0)
		{
			return -1;
		}
	}
	return count[4];
}
int main()
{
	string s = countAndSay(4);
	return 0;
}